home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
edit
/
xvisrc.zip
/
IBMPC_A.ASM
< prev
next >
Wrap
Assembly Source File
|
1992-07-28
|
20KB
|
966 lines
; Copyright (c) 1990,1991,1992 Chris and John Downey
_TEXT segment word public 'CODE'
db "@(#)ibmpc_a.asm 2.1 (Chris & John Downey) 7/29/92"
db 0
_TEXT ends
;***
;
; program name:
; xvi
; function:
; PD version of UNIX "vi" editor, with extensions.
; module name:
; ibmpc_a.asm
; module function:
; Assembly language part of terminal interface module for IBM PC
; compatibles running MS-DOS.
;
; This code has been assembled with Microsoft's Macro Assembler
; (MASM) version 5.1, & is compatible with code generated by
; MS-DOS C compilers using the normal large memory model calling
; conventions. This includes the Microsoft & Zortech compilers.
;
; If we're running on a mono system, or one with an EGA or VGA,
; & we were started in a text mode, we can achieve much faster
; display output by writing directly to the frame buffer; we can
; also save the previous screen contents & restore them when we
; exit or run a sub-shell, which can be useful. If we have a
; CGA, or we were started in a graphics mode, we just use the
; functions supplied by the PC BIOS, which are slower, but good
; enough for most purposes. On a modern 80386-based system, the
; difference in speed is hardly noticeable.
; history:
;
; STEVIE - ST Editor for VI Enthusiasts, Version 3.10
; Originally by Tim Thompson (twitch!tjt)
; Extensive modifications by Tony Andrews (onecom!wldrdg!tony)
; Heavily modified by Chris & John Downey
;***
include 8086mm.inc
;
; If SWAPSCREEN is defined, we attempt to save the previous screen
; image & restore it when we exit or run another process. If you don't
; want this to happen, just comment out the line below.
;
SWAPSCREEN equ 1
;
; If you don't want mouse input handling, comment out the line below.
;
MOUSE equ 1
C_extern _malloc
C_extern _cparams
public _alert
public _erase_display
public _erase_line
public _flush_output
public _hidemouse
public _mousestatus
public _outchar
public _outstr
public _scroll_up
public _scroll_down
public _set_colour
public _showmouse
public _tty_endv
public _tty_goto
public _tty_open
public _tty_startv
;
; Segment addresses for PC text mode frame buffer.
;
VMONOSEG = 0b000h ; Mono frame buffer.
VCOLOURSEG = 0b800h ; Colour frame buffer.
;
; BIOS video functions.
;
vbios macro ahval, alval
ifnb <ahval>
ifnb <alval>
mov ax, (ahval shl 8) + alval
else
mov ah, ahval
endif
endif
int 10h
endm
;
; BIOS video function numbers.
;
B_MOVECURSOR = 2 ; Move cursor.
B_UPSCROLL = 6 ; Scroll window up.
B_DOWNSCROLL = 7 ; Scroll window down.
B_WRITECHAR = 9 ; Write character & attribute at
; current position.
B_TTYWRITE = 0eh ; Teletype-style write.
B_GETMODE = 0fh ; Get video mode.
B_SETPALETTE = 10h ; Set palette registers.
B_EGACGEN = 11h ; EGA character generator.
B_VCONFIG = 12h ; Video subsystem configuration.
;
; Subfunction (of function 10h) for setting overscan register.
;
B_OVERSCAN = 1
;
; Subfunctions for EGA character generator.
;
B_EGATEST = 30h
B_8X8FONT = 12h
B_8X14FONT = 11h
;
; BIOS function to use alternate print screen routine.
;
altpscreen macro
mov bl, 20h
vbios B_VCONFIG
endm
;
; BIOS function to get equipment list.
;
biosequip macro
int 11h
endm
;
; Value returned by biosequip (in ax) to indicate a mono display.
;
EQUIP_MONO = 30h
;
; Default number of rows in text modes.
;
DEF_T_ROWS = 25
;
; Video modes.
;
BWT25X80 = 2 ; 25 x 80 black & white (CGA) text.
CT25X80 = 3 ; 25 x 80 colour text.
MT25X80 = 7 ; 25 x 80 monochrome (MDA) text.
;
; I/O ports.
;
TIMER_2 = 42h ; Timer channel 2.
TIMER_3 = 43h ; Timer channel 3.
PORT_B = 61h ; 8255 port B.
;
; Interrupt used by Microsoft mouse driver.
;
MSMINT = 33h
;
; Call mouse driver.
;
msmouse macro funcnum
ifnb <funcnum>
mov ax, funcnum
endif
int MSMINT
endm
;
; Mouse driver function numbers.
;
MSM_SHOW = 1
MSM_HIDE = 2
MSM_GETSTATUS = 3
MSM_SETYLIMITS = 8
;
; Values for mouseflag.
;
MF_NOMOUSE = -1
MF_INITIAL = 0
MF_OK = 1
MF_VISIBLE = 2
;
; Segment containing interrupt vector table.
;
INTVECTAB segment at 0
;
; Vector used by Microsoft mouse driver.
;
org (MSMINT * 4)
msvecoff dw ?
msvecseg dw ?
INTVECTAB ends
;
; BIOS variable data segment.
;
BVSEG = 40h
BIOSDATA segment at BVSEG
;
; Low word of timer variable.
;
org 6ch
b_timer_low dw ?
;
; Variable giving number of screen rows - 1.
;
org 84h
b_rowsvar db ?
BIOSDATA ends
_TEXT segment word public 'CODE'
assume nothing
assume cs: _TEXT
even
ifdef SWAPSCREEN
saveptr label dword ; Pointer to saved screen image.
svboff dw 0
svbseg dw 0
scrwords dw ? ; Number of 2-byte words in saved
; screen image.
endif ; SWAPSCREEN
vbase dw 0 ; Segment address of frame buffer. If
; this is 0, we don't access the frame
; buffer directly.
vcolumn label byte
vpos dw ? ; Virtual screen position.
scrsize label word ; Screen dimensions.
ncolumns db ? ; Low byte of scrsize.
nrows db ? ; High byte of scrsize.
writemethod dw offset bioswrite
; Pointer to function we use for
; outputting characters to the screen.
startmode db ?
ega db 0 ; Flag indicating presence of EGA/VGA.
vcolour db ? ; Virtual colour.
ifdef MOUSE
mouseflag db MF_INITIAL
; This is changed by _tty_startv to
; MF_OK if we have a mouse driver
; installed, or MF_NOMOUSE if we
; haven't.
else ; MOUSE
mouseflag db MF_NOMOUSE
endif ; MOUSE
ifdef SWAPSCREEN
;
; These routines deal with saving the previous screen image &
; restoring it.
;
savescreen:
cmp vbase, 0
je dontcopy
push si
push di
push ds
les di, saveptr
mov ax, es
or ax, di
jz cps_pop
mov ds, vbase
clear si
jmp short copyscreen
restorescreen proc near
cmp vbase, 0
je dontcopy
push si
push di
push ds
mov es, vbase
clear di
lds si, saveptr
mov ax, ds
or ax, si
jz cps_pop
copyscreen:
mov cx, scrwords
cld
rep movsw
cps_pop:
pop ds
pop di
pop si
dontcopy:
ret
restorescreen endp
endif ; SWAPSCREEN
even
_flush_output:
;
; void flush_output(void);
;
; Update real cursor position.
;
push bp
mov dx, vpos
clear bh ; Display page 0.
vbios B_MOVECURSOR
pop bp
C_ret
even
_erase_line:
;
; void erase_line(void);
;
; Erase to end of line.
;
; Don't update cursor position.
;
mov cl, ncolumns ; Get width of screen.
mov al, vcolumn ; Get current column.
sub cl, al ; Number of spaces to write ...
jz noerase ; ... except if it's 0 ...
clear ch
mov al, ' '
cld
call [writemethod]
noerase:
C_ret
_erase_display:
;
; void erase_display(void);
;
; Erase entire display by using BIOS scroll screen
; function to scroll all the lines in the display.
;
; Don't update cursor position.
;
call _cparams ; This is in ibmpc_c.c.
mov bh, al ; Get colour for blank screen.
push bp
clear cx ; Top left row & column (0).
mov al, nrows ; Number of lines (0).
mov dx, scrsize
dec dh ; Bottom right row.
dec dl ; Bottom right column.
vbios B_UPSCROLL
pop bp
C_ret
even
_showmouse:
;
; void showmouse(void);
;
; Show mouse cursor.
;
; If we don't seem to have a mouse driver, or we think
; the cursor is already visible, don't do anything.
;
cmp mouseflag, MF_OK
jne m_invalid
mov ax, MSM_SHOW
mov mouseflag, MF_VISIBLE
m_valid:
msmouse
m_invalid:
C_ret
even
_hidemouse:
;
; void hidemouse(void);
;
; Hide mouse cursor.
;
; If we don't seem to have a mouse driver, or we don't
; think the cursor is visible, don't do anything.
;
cmp mouseflag, MF_VISIBLE
jne m_invalid
mov ax, MSM_HIDE
mov mouseflag, MF_OK
jmp short m_valid
_mousestatus:
;
; unsigned mousestatus(unsigned *xpos, unsigned *ypos);
;
; Return mouse button status, with current mouse
; co-ordinates in *xpos & *ypos.
;
push bp
mov bp, sp
cmp mouseflag, MF_OK
jge getstatus ; if it's MF_OK or MF_VISIBLE
clear ax ; Button status = 0.
cwd ; y co-ordinate = 0.
mov cx, ax ; x co-ordinate = 0.
jmp short ms_finish
getstatus:
msmouse MSM_GETSTATUS
mov ax, bx ; Return button status in ax.
ms_finish:
;
; Stack frame:
;
; bp + CPTRSIZE + DPTRSIZE + 2
; ypos pointer